package faf.web.tests;

import junit.framework.TestCase;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;

import faf.business.UserManager;
import faf.dao.JpaUtils;
import faf.entities.Account;
import faf.web.UpdateAccountController;
import faf.web.data.NewAccountForm;

/**
 * @author Pierre-Olivier Pignon
 * @date 11 mars 2011 � 10:16:36
 *
 */
public class UpdateAccountControllerTests extends TestCase {
	
	private final Logger logger = LoggerFactory.getLogger(UpdateAccountControllerTests.class);
	private static UpdateAccountController controller=null;
	static JpaUtils jpautils;
	static UserManager userManager; 
	
	@Before
	public static void setUpBeforeClass() throws Exception {
		UserManager userManager = new UserManager();
		userManager.setJpautils(jpautils);
		controller = new UpdateAccountController();
	}
	
/*	@Test
	public void testHandleRequestView() throws Exception{
		
		logger.info("Debut du test du controller ");
		
		ModelAndView modelAndView = controller.handleRequest(null,null);
		logger.info( modelAndView.getViewName());
        //assertEquals("WEB-INF/updateAccount.htm", modelAndView.getViewName());
        assertNotNull(modelAndView.getModel());
        
    }*/


	/**
	 * Test method for {@link faf.web.UpdateAccountController#formBackingObject(javax.servlet.http.HttpServletRequest)}.
	 */
	@Test
	public void testFormBackingObjectHttpServletRequest() {
		long account_id = 1;

		Account account = new Account();
		assertNotNull(userManager);
		account = userManager.findAccount(account_id);
		assertNotNull(account);
		assertTrue(account.getFirstname().equalsIgnoreCase("pop"));
		NewAccountForm accountForm = new NewAccountForm();
		if (account != null) {

			accountForm.setEmail(account.getMail());
			accountForm.setFirstname(account.getFirstname());
			accountForm.setLastname(account.getLastname());
		}
		
	}

	/**
	 * Test method for {@link faf.web.UpdateAccountController#onSubmit(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object, org.springframework.validation.BindException)}.
	 */
	@Test
	public void testOnSubmitHttpServletRequestHttpServletResponseObjectBindException() {
		fail("Not yet implemented");
	}

}
